


/**********       ***********
1.2010-01-07     original

***************************************/
#include "sys_header.h"

#ifndef  DRIVER_POWER_CONTROL_H_
#define  DRIVER_POWER_CONTROL_H_



typedef unsigned char  UC;
typedef unsigned short int   UI;


/***************************************************************/

#define LTC4261_CURRENT_RATIO  19  	//base on the registors 
                                                             //1000
#define LTC4261_VOLTAGE_RATIO  43 	//base on the registors connect to OV pin
                                                           //400
#define LTC4222_MCH_CUR_RATIO  62   //MCH 10000 times
#define LTC4222_CU_CUR_RATIO   19   //CU  10000 times
#define LTC4222_AMC_CUR_RATIO  42   //AMC 10000 times
#define LTC4222_VOLTAGE_RATIO  31   //1000 times

#define CURRENT_EVENT_LIMIT		5000	/* 5000mA,is about 60W. */

/****************************************************************/
#define CMD_STATUS             	0x00
#define CMD_INPUT               0x01
#define CMD_OUTPUT            	0x02
#define CMD_CURRENT           	0x03
#define CMD_CONTROL           	0x04
#define CMD_ALERT               0x05
#define CMD_FAULT               0x06
#define CMD_ADCCON				0x07

/*********************************************/
#define MAX_PP_CHAN	16
#define PP_MCH1                   1
#define PP_MCH2                   2
#define PP_CU1                      3
#define PP_CU2                      4
#define PP_AMC1                   5
#define PP_AMC2                   6
#define PP_AMC3                   7
#define PP_AMC4                   8
#define PP_AMC5                   9
#define PP_AMC6                   10
#define PP_AMC7                   11
#define PP_AMC8                   12
#define PP_AMC9                   13
#define PP_AMC10                 14
#define PP_AMC11                 15
#define PP_AMC12                 16

/****************************************************************************/
/********************** ltc4261  ************************/
#define LTC4261_ADDR 0x20		//8 bits slave address;	//0x10  //HARDWARE CONFIG (ADR1 =L,ADR0 =L)

/********************** ltc4261 ************************/
#define LTC4261_STATUS     0x00
#define LTC4261_FAULT       0x01
#define LTC4261_ALERT       0x02
#define LTC4261_CONTROL   0x03
#define LTC4261_SENSE_H   0x04
#define LTC4261_SENSE_L    0x05
#define LTC4261_ADIN2_H    0x06
#define LTC4261_ADIN2_L    0x07
#define LTC4261_ADIN_H      0x08
#define LTC4261_ADIN_L      0x09

/****************************************************************************/
/*-----------ltc4222  --------------------*/
#define LTC4222_CHIP_01      0xb8		//8 bits slave address;	//0x5c  //for MCH1-2 PP
#define LTC4222_CHIP_02      0xba		//0x5d  //for CU  1-2 PP
#define LTC4222_CHIP_03      0xbc		//0x5e  //for AMC1-2 PP
#define LTC4222_CHIP_04      0xbe		//0x5f  //for AMC3-4 PP
#define LTC4222_CHIP_05      0xc8		//0x64  //for AMC5-6 PP
#define LTC4222_CHIP_06      0xca		//0x65  //for AMC7-8 PP
#define LTC4222_CHIP_07      0xcc		//0x66  //for AMC9-10 PP
#define LTC4222_CHIP_08	     0xce		//0c67 //for AMC11-12 PP

/*-----------ltc4222  --------------------*/
#define LTC4222_CONTROL1   0xD0    
#define LTC4222_ALERT1        0xD1    
#define LTC4222_STATUS1     0xD2    
#define LTC4222_FAULT1        0xD3    

#define LTC4222_CONTROL2   0xD4    
#define LTC4222_ALERT2        0xD5    
#define LTC4222_STATUS2     0xD6    
#define LTC4222_FAULT2        0xD7    

#define LTC4222_SOURCE_H1   0xD8    
#define LTC4222_SOURCE_L1    0xD9    

#define LTC4222_SOURCE_H2   0xDA    
#define LTC4222_SOURCE_L2    0xDB        
/*
#define LTC4222_ADIN_H1     0xDC    //adin
#define LTC4222_ADIN_L1      0xDD    
#define LTC4222_ADIN_H2     0xDE   
#define LTC4222_ADIN_L2      0xDF    
*/
#define LTC4222_SENSE_H1   0xE0    
#define LTC4222_SENSE_L1    0xE1    

#define LTC4222_SENSE_H2   0xE2    
#define LTC4222_SENSE_L2    0xE3       

#define LTC4222_ADC_CON    0xE4

#define LTC4222_CNT_PRM	0x5B
#define LTC4222_CNT_BAK	0x7B
#define LTC4222_CNT_OFF	0x73

/**********************************************************/
/**************** defined for BMR453 **********************/
#define BMR453_CURRENT_RATIO  1000   //????????1000?
#define BMR453_VOLTAGE_RATIO  400     //????????400?


/********************** BMR453 chip address ************************/
#define BMR453_ADDR 		0x3a		// 8 bits addrs;		//0x1d  //7bits I2C address ;

/********************** BMR453 PMBus command ************************/
#define BMR453_VOUT_MODE            0x20
#define BMR453_VOUT_COMMAND     	0x21
#define BMR453_READ_VIN             0x88
#define BMR453_READ_VOUT            0x8B
#define BMR453_READ_IOUT            0x8C

#define BMR453_LINEAR_FORMAT     	0x15//set to linear mode & V= vout_command /1024
#define BMR453_MAIN_VOLTAGE       	0x5800 //MAIN POWER voltage setpoint = 12.6V
#define BMR453_REDUNDANCY_VOLTAGE   0x5000 //redundancy power voltage setpoint =11.8V
#define CMD_SET_MAINPOWER         	0x07   //for BMR453
#define CMD_SET_REDUNDANCY       	0x08  //for BMR453


/*-----------------Bmr453 --------------*/
XStatus ReadBMR453(Xuint8 cmd,Xuint16 * p_data);
XStatus Master_Select_Bmr453(Xuint8 master);
Xuint16 BMRDataProcess1(Xuint16 ratio, Xuint8 data1,Xuint8 data2);
XStatus Init_Bmr453();

/*-----------------Ltc4261 --------------*/

XStatus ReadLtc4261(Xuint8 cmd,Xuint16 *data);
XStatus WriteLtc4261(Xuint8 cmd,Xuint8 data);

Xuint16 Ltc4261DataProcess(Xuint16 ratio, Xuint8 data1,Xuint8 data2);


/*-----------------Ltc4222 --------------*/
XStatus ReadLtc4222(Xuint8 channel,Xuint8 cmd,Xuint16* p_data);
XStatus WriteLtc4222(Xuint8 channel,Xuint8 cmd,Xuint8 data);
void Ltc4222AddrProcess(Xuint8 * temp);
Xuint8 Ltc4222RegAddrProcess1(Xuint8 command);
Xuint8 Ltc4222RegAddrProcess2(Xuint8 command);
XStatus Enable_Payload_Power(Xuint8 channel_num,Xuint8 enable,Xuint8 master);
Xuint16 Get_Payload_Power_Status(Xuint8 channel_num);
XStatus Master_Select_Ltc4222(Xuint8 channel_num,Xuint8 master);
XStatus Set_Pm_Role(Xuint8 ena);

#endif /*DRIVER_POWER_CONTROL_H_*/



